(function($){
//今日上新  购物车
$(window).load(function(){
//判断用户是否登录，如果登录成功，则获取cookie中的用户名并显示到登录和注册的地方；
	if($.cookie('isLogin')=='true'){
		$('.header-user').html('<a href="javascript:;" class="login">欢迎您，15201061391</a><a href="javascript:;" class="exit">[退出]</a><span class="line">|</span><a href="javascript:;" class="register">我的订单</a><span class="line">|</span><a href="javascript:;" class="register">购物车</a><span class="line">|</span><a href="javascript:;" class="register">我的收藏</a><span class="line">|</span><span class="ico-phone"></span>400-080-1888<span class="line">|</span><a href="javascript:;" class="da">下载达令<div class="download"><span class="arrow-7-5"></span><span class="pic-code"></span></div></a>')
//点击退出按钮，清空cookie中的登录判断isLogin
		$('.exit').click(function(){
			$.cookie('isLogin',null,{path:'/'});
			window.location.href='list.html';
		})
	}
//判断cookie中购物车的数量，并同步到页面
	$('.banner-cart-count').text($.cookie('count'));
	$('.mtp2-dl').mouseover(function(){
		var inds = $(this);
		inds.find('.mtp2-dl-shop').css('display' , 'block');
	});
	$('.mtp2-dl').mouseout(function(){
		$(this).find('.mtp2-dl-shop').css('display' , 'none');
	});
//导航栏全部分类移入移出事件
	$('.category').hover(function(){
		$('.category .dd').css('display','block');
		$('.icon-down').css('display','inline-block');
		$('.icon-up').css('display','none');
	},function(){
		$('.category .dd').css('display','none');
		$('.icon-down').css('display','none');
		$('.icon-up').css('display','inline-block');
	})
//后添加上的小米搜索框;
	var
		oSeachContent = $('.s-keyword'),
		oSearchList   = $('#search-list'),
		iSearchIndex  = -1,
		sOriHtml 	  = oSearchList.html();
	oSeachContent.focus(function () {
		oSearchList.css('display', 'block');
	}).blur(function () {
		oSearchList.css('display', 'none');
	}).keyup(function (ev) {
		var
			ev = ev || window.event,
			aLi = $('#search-list li');
		if(ev.keyCode === 38 || ev.keyCode === 40) {
			if(ev.keyCode === 38 && iSearchIndex > 0) {
				iSearchIndex--;
			} else if(ev.keyCode === 40 && iSearchIndex < aLi.length - 1) {
				iSearchIndex++;
			}
			oSeachContent.val(aLi.removeClass('active').eq(iSearchIndex).addClass('active').data('key'));
		}
	}).bind('input propertychange', function () {
		var sSearchCon = $(this).val();
		if(sSearchCon) {
			$.ajax({
				url: 'http://search.mi.com/search/expand',
				data: {keyword: sSearchCon},
				jsonp: 'jsonpcallback',
				dataType: 'jsonp',
				success: function (data) {
					var sHtml = '';
					data.forEach(function (v) {
						sHtml += '<li data-key="' + v.Key + '"><a href="javascript:;"><span>约有' + v.Rst + '件</span>' + v.Key + '</a></li>';
					});
					if(sHtml) {
						oSearchList.css('display', 'block').html(sHtml);
					} else {
						oSearchList.css('display', 'none');
					}
					iSearchIndex = -1;
				}
			});
		} else {
			oSearchList.html(sOriHtml);
			iSearchIndex = -1;
		}
	});
})
	
})(jQuery)	